var mf = null;
var mw = null;
window.addEvent('domready', myMooFlowPage.start);
window.onresize = resize;
//test browser type
var user = navigator.userAgent;
var browser = {};
browser.opera = user.indexOf("Opera") > -1 && typeof window.opera == "object";
browser.ie = user.indexOf("MSIE") > -1 && !browser.opera;
browser.ff = user.indexOf("Firefox") > -1;
browser.chrome = user.indexOf("Chrome") > -1;
browser.safari = user.indexOf("Safari") > -1;
var ifWatchMovie = false;
var ifRegist = false;
var ifLogin = false;
var regist_email = false;
var regist_pass = false;
var login_email = false;
var login_pass = false;
var has_click_login_pass = false;
var has_click_regist_pass = false;
var window_event;
$j(document).keydown(esc)

var drag = false; //whether the mouse is within the area of video title
var move = false; //moving the title to add into fav
var dragObj;
$j(document).mousemove(mouseMove);
$j(document).mousedown(mouseDown);
$j(document).mouseup(mouseUp);
window.document.ondragstart = mouseStop;
var playerCoverContentLeft;
var playerCoverContentTop;
var playerCoverContentRight;
var playerCoverContentBottom;
var playerCoverBottom;
var videoPlayLink;
var videoID;
var titleHeight = 45;
var videoTitle;
var LargestListsNumber = 8;
var videoTitleLength;
var videoTitleLeft1;
var videoTitleLeft2;
var dragActivateAreaLeft;
var dragActivateAreaTop;
var dragActivateAreaRight;
var dragActivateAreaBottom;
var favAreaLeft;
var favAreaRight;
var favAreaTop;
var favAreaBottom;
var favListsLeft;
var favListsRight;
var favListsTop;
var favListsBottom;
var plusOneFloat = 400;
var plusOneDisappear = 1200;
var titleWordsHeight = 14;
var knobWidth = 0;

var watchType = 1;//1 means system_rec, 2 means friend_rec, 3 means serialize, 4 means fav
var favTitleHeight;
var mouseX;
var mouseY;
var user_fav_pos = 0;
var user_fav_lists = [];
var favType = "所有收藏";
var tempfavType;
var favListLefts = [];
var favListRights = [];
var favListTops = [];
var favListBottoms = [];
var favListNormalColor = 'rgb(0, 0, 0)';
var favListNormalColorIE = 'rgb(0,0,0)';
var favListScanColor = 'rgb(90, 90, 90)';
var favListScanColorIE = 'rgb(90,90,90)';
var favListSelectPos = 0;
var tempfavListSelectPos;
var favListLoadOver = false;
var ifShowPreList = false;
var favListsHeight;
var preListTop = 0;
var preListLeft = 0;
var preListBottom = 0;
var preListRight = 0;
var nextListTop = 0;
var nextListLeft = 0;
var nextListBottom = 0;
var nextListRight = 0;
var newFavListTop = 0;
var newFavListLeft = 0;
var newFavListRight = 0;
var newFavListBottom = 0;
var favListStartPos = 0;
var favListEndPos;
var ifWantPreFavList = false;
var preFavTimeOut;
var ifWantNextFavList = false;
var nextFavTimeOut;
var originalPasswordState = false;
var newPasswordState = false;
var favListWidth = 190;
var favListHeight = 30;
var confirmListName;
var clickDelete;
var favListClickTime = 0;
var favListClickTimer = -1;
var favlistsOpacity = 0.9;
var pre_user_fav_pos = -1;
var system_rec_type = 0; //0 means personal, 1 means popularity
var watch_movie_image_source;
var pleaseEnterListName = true;
var watchVideoStart;
var watchVideoEnd;
var watchVideoId;
var watchVideoType = 0;//0 means personal, 1 means popularity, 2 means fav



function loadImages()
{
    var preload_img0 = new Image();
    preload_img0.src = "ico/button.png";
    var preload_img1 = new Image();
    preload_img1.src = "ico/button_mouseon.png";
    var preload_img2 = new Image();
    preload_img2.src = "ico/button_click.png";
    var preload_img3 = new Image();
    preload_img3.src = "ico/reg_button_mouseon.png";
    var preload_img4 = new Image();
    preload_img4.src = "ico/reg_button_click.png";
    var preload_img5 = new Image();
    preload_img5.src = "ico/remove.png";
    var preload_img6 = new Image();
    preload_img6.src = "ico/remove_click.png";
    var preload_img7 = new Image();
    preload_img7.src = "ico/remove_mouseon.png";
    var preload_img8 = new Image();
    preload_img8.src = "ico/share/renren.png";
    var preload_img9 = new Image();
    preload_img9.src = "ico/go.png";
    var preload_img10 = new Image();
    preload_img10.src = "ico/go_mouseon.png";
    var preload_img11 = new Image();
    preload_img11.src = "ico/go_click.png";
    var preload_img12 = new Image();
    preload_img12.src = "ico/title_bg.png";
    var preload_img13 = new Image();
    preload_img13.src = "ico/title_bg_mouseon.png";
    var preload_img14 = new Image();
    preload_img14.src = "ico/title_bg_clickon.png";
    var preload_img15 = new Image();
    preload_img15.src = "ico/drag.png";
    var preload_img16 = new Image();
    preload_img16.src = "ico/video_edge.png";
    var preload_img17 = new Image();
    preload_img17.src = "ico/video_edge_top2.png";
    var preload_img18 = new Image();
    preload_img18.src = "ico/plus1.png";
    var preload_img19 = new Image();
    preload_img19.src = "ico/apple.png";
    var preload_img20 = new Image();
    preload_img20.src = "ico/ImageWall/cancel_fav.png";
    var preload_img21 = new Image();
    preload_img21.src = "ico/ImageWall/cancel_fav_mouseon.png";
    var preload_img22 = new Image();
    preload_img22.src = "ico/ImageWall/cancel_fav_click.png";
    var preload_img23 = new Image();
    preload_img23.src = "ico/tutorial.png";
}

function getUserFavLists()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if (xmlhttp.responseText == "NOUSER")
			{
			}
			else
			{
                var start = 0;
                var end = xmlhttp.responseText.indexOf(':;', start);
                while (end != -1)
                {
                    user_fav_lists.push(xmlhttp.responseText.substring(start, end));
                    start = end + 2;
                    end = xmlhttp.responseText.indexOf(':;', start);
                }
                favListLoadOver = true;
			}
    	}
  	}
	xmlhttp.open("POST","getUserFavLists.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send("");
}

function esc(e)
{
	if (e.keyCode == 27)
	{
		if (ifWatchMovie)
		{
			clearmovie();
		}
		if ($('regist_close'))
		{
			clearregist($('regist_close'));	
		}
        if ($('changePassword'))
        {
            closeChangePassword();
        }
	}
}

function clearmovie()
{
	ifWatchMovie = false;
    $j('#videoplayer').remove();
    if ($j('#renren_share'))
    {
        $j('#renren_share').remove();
        watchVideoEnd = new Date();
        var s = (watchVideoEnd.getTime() - watchVideoStart.getTime()) / 1000;
        track_watch_video(watchVideoId, s);
    }
    if ($j('#weibo_share'))
    {
        $j('#weibo_share').remove();
    }
    if ($j('#tencentweibo_share'))
    {
        $j('#tencentweibo_share').remove();
    }
    if ($j('#qqkongjian_share'))
    {
        $j('#qqkongjian_share').remove();
    }
	$('playwindow_scanlist_center').setStyle('z-index', -1);
	$('playwindow_background_center').tween('opacity', 0);
	$('playwindow_background_center').setStyle('z-index', 0);
	$('removemovie').setStyle('visibility', 'hidden');
    if ($j('#player_cover'))
    {
        $j('#player_cover').remove();
    }
    if ($j('#player'))
    {
        $j('#player').remove();
    }
    if ($j('#dragimg'))
    {
        $j('#dragimg').remove();
    }
}

function track_watch_video(videoid, period)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	/*xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
            alert(xmlhttp.responseText);
    	}
  	}*/
	xmlhttp.open("POST","track_user_watch_video.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send("videoid=" + videoid + "&period=" + period + '&watchType=' + watchVideoType);
}

function ClickToRemoveMovie()
{
	clearmovie();
}

function systembuttonover(o)
{
    if (!move)
    {
    	if (browser.ie)
    		o.style.backgroundImage = "url('ico/button_mouseon.png')";
    	else
    		o.setStyle('background-image', 'url(ico/button_mouseon.png)');
        $('sys_rec_lists').setStyle('opacity', favlistsOpacity);
    }
}
function systembuttonout(o)
{
	if (browser.ie)
		o.style.backgroundImage = "";
	else
		o.setStyle('background-image', '');
    $('sys_rec_lists').setStyle('opacity', 0);
}

function systemRecList()
{
    var listheight = 2 * favListHeight;
    $("sys_rec_lists").setStyle("height", listheight);
    var syslist = new Element('div', {'id':'popularity_list', 'class':"fav_list"}).inject($('sys_rec_lists'));
    $('popularity_list').innerHTML = '热门视频';
    new Element('div', {id:"popularity_list_watch", 'class':"system_rec_list_watch"}).inject($('popularity_list'));
    $j('#popularity_list_watch').css('opacity', 0);
    var personlist = new Element('div', {'id':'personal_list', 'class':"fav_list"}).inject($('sys_rec_lists'));
    $('personal_list').innerHTML = '猜你喜欢';
    new Element('div', {id:"personal_list_watch", 'class':"system_rec_list_watch"}).inject($('personal_list'));
    $j('#personal_list_watch').css('opacity', 1);
    $('personal_list').setStyles({
        'border-bottom-width':'0px',
        'height':'24px'
    });
    $j('#popularity_list').mouseover(function() {sysRecListMouseOver('popularity_list');});
    $j('#popularity_list').mouseout(function() {sysRecListMouseOut('popularity_list');});
    $j('#popularity_list').click(popularityClick);
    $j('#personal_list').mouseover(function() {sysRecListMouseOver('personal_list');});
    $j('#personal_list').mouseout(function() {sysRecListMouseOut('personal_list');});
    $j('#personal_list').click(personalClick);
    $('sys_rec_lists').setStyle('opacity', 0);
}

function popularityClick()
{
    system_rec_type = 1;
    watchVideoType = 1;
    system_rec_click();
    $j('#personal_list_watch').css('opacity', 0);
    $j('#popularity_list_watch').css('opacity', 1);
}

function personalClick()
{
    system_rec_type = 0;
    watchVideoType = 0;
    system_rec_click();
    $j('#popularity_list_watch').css('opacity', 0);
    $j('#personal_list_watch').css('opacity', 1);
}
function sysRecListMouseOver(element)
{
    $(element).setStyle('background-color', favListScanColor);
}

function sysRecListMouseOut(element)
{
    $(element).setStyle('background-color', favListNormalColor);
}

function favbuttonover(o)
{
    if (!move)
    {
    	if (browser.ie)
        {
    		o.style.backgroundImage = "url('ico/button_mouseon.png')";
        }
    	else
    		o.setStyle('background-image', 'url(ico/button_mouseon.png)');
        if (!$("list0"))
        {
            addUserFavList();
        }
        var name = "createNewList";
        if ($(name))
        {
            if ($(name).innerHTML == "创建新列表")
            {
                changeUserFavLists(0);
            }
            else
            {
                changeUserFavLists(1);
            }
        }
    }
}

function favbuttondown(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/button_click.png')";
	else
		o.setStyle('background-image', 'url(ico/button_click.png)');
}
function favbuttonup(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/button_mouseon.png')";
	else
		o.setStyle('background-image', 'url(ico/button_mouseon.png)');
}
function favbuttonout(o)
{
    if (!move)
    {
	    if (browser.ie)
        {
		    o.style.backgroundImage = "";
        }
	    else
	        o.setStyle('background-image', '');
        $("favlists").set('tween', {duration: 200});
        $("favlists").tween("opacity", 0);
    }
}

function addUserFavList()
{
    if (!favListLoadOver)
    {
        setTimeout(function() {addUserFavList()},1000);
    }
    else
    {
        favListStartPos = 0; 
        if (user_fav_lists.length <= LargestListsNumber)
        {
            ifShowPreList = false;
            favListsHeight = user_fav_lists.length * favListHeight + favListHeight;
            favListEndPos = user_fav_lists.length;
        }
        else
        {
            ifShowPreList = true;
            favListsHeight = 9 * favListHeight;
            favListEndPos = 6;
        }
        $("favlists").setStyle("height", favListsHeight);
        $j('#favlists').empty();
        favListLefts = [];
        favListTops = [];
        favListRights = [];
        favListBottoms = [];
        var listheight;
        if (user_fav_lists.length <= LargestListsNumber)
        {
            listheight = user_fav_lists.length * favListHeight;
        }
        else
        {
            listheight = 6 * favListHeight;
            var pre = new Element('div', {'id':'prelist', 'class':'fav_list'}).inject($('favlists')).setStyles({'text-align':'center', 'padding-left':'0px'});
            pre.innerHTML = "<img src='ico/over.png' />";
            preListLeft = $j('#prelist').offset().left;
            preListTop = $j('#prelist').offset().top;
            preListRight = $j('#prelist').offset().left + favListWidth;
            preListBottom = $j('#prelist').offset().top + favListHeight;
        }
        var lists = new Element('div', {'id':'lists'}).inject($('favlists')).setStyles({'width':favListWidth+'px', 'height':listheight+"px", 'overflow':'hidden'});
        var lists_content = new Element('div', {'id':'lists_content'}).inject($('lists')).setStyles({'position':'relative', 'width':favListWidth+'px', 'height':(user_fav_lists.length * favListHeight)+"px"});
        for (var i = 0; i < user_fav_lists.length; ++i)
        {
            var name = "list" + i;
            var list = new Element('div', {'id':name, 'class':"fav_list"}).inject($('lists_content'));
            $j('#' + name).attr('title', user_fav_lists[i]);
            $j('#' + name).click(clickFavType);
            var listname = new Element('div', {'id':'listname'+i, 'class':"listname unselectable"}).inject($(name));
            var listname_content = new Element('div', {'id':'listname_content'+i, 'class':"listname_content unselectable"}).inject(listname);
            $j('#listname_content'+i).attr('unselectable', 'on');
            listname_content.innerHTML = getFavListVisible(user_fav_lists[i]);
            var watching = new Element('div', {id:"fav_list_watch"+i, 'class':"fav_list_watch"}).inject($(name));
            $j('#fav_list_watch'+i).css('opacity', 0);
            if (i + 1 < user_fav_lists.length)
            {
                var deleting = new Element('div', {id:"fav_list_delete"+i, 'class':"fav_list_delete"}).inject($(name));
                $j('#fav_list_delete'+i).click(clickDeleteFavList);
                $j('#fav_list_delete'+i).mouseout(deleteFavListMouseOut);
                $j('#fav_list_delete'+i).css('opacity', 0);
                if (browser.ie)
                {
                    $j('#listname'+i).dblclick(dbclickRename);
                }
            }
            favListLefts.push($j('#'+name).offset().left);
            favListTops.push($j('#'+name).offset().top);
            favListRights.push($j('#'+name).offset().left + favListWidth);
            favListBottoms.push($j('#'+name).offset().top + favListHeight);
        }
        if (user_fav_lists.length > LargestListsNumber)
        {
            var next = new Element('div', {'id':'nextlist', 'class':'fav_list'}).inject($('favlists')).setStyles({'text-align':'center', 'padding-left':'0px'});
            next.innerHTML = "<img src='ico/down.png' />";
            nextListLeft = $j('#nextlist').offset().left;
            nextListTop = $j('#nextlist').offset().top;
            nextListRight = $j('#nextlist').offset().left + favListWidth;
            nextListBottom = $j('#nextlist').offset().top + favListHeight;
        }
        var name = 'createNewList';
        var createNew = new Element('div', {'id':name, 'class':'fav_list'}).inject($('favlists'));
        createNew.innerHTML = "创建新列表";
        $(name).setStyles({
            'border-bottom-width':'0px',
            'height':'24px'
        });
        favListsLeft = $j('#favlists').offset().left;
        favListsTop = $j('#favlists').offset().top;
        favListsRight = $j('#favlists').offset().left + favListWidth;
        favListsBottom = $j('#favlists').offset().top + favListsHeight;
        newFavListTop = $j('#'+name).offset().top;
        newFavListLeft = $j('#'+name).offset().left;
        newFavListRight = $j('#'+name).offset().left + favListWidth;
        newFavListBottom = $j('#'+name).offset().top + favListHeight;
    }
}


function clickDeleteFavList()
{
    clickDelete = true;
    var message = "确定要将\"" + user_fav_lists[user_fav_pos] + "\"列表删除？";
    myConfirm(message, 'deleteFavList()', user_fav_lists[user_fav_pos]);
}

function deleteFavListMouseOut()
{
    clickDelete = false;
}

function clickPre()
{
    if (favListStartPos > 0)
    {
        favListStartPos = favListStartPos - 1;
        favListEndPos = favListEndPos - 1;
        refreshListsPos(favListHeight);
        if (favListStartPos == 0)
        {
            $('prelist').innerHTML = "<img src='ico/over.png' />";
        }
        if (favListEndPos < user_fav_lists.length)
        {
            $('nextlist').innerHTML = "<img src='ico/down.png' />"
        }
        setTimeout(function() {
            $("lists_content").set('tween', {duration: 200});
            $("lists_content").tween("top", (-1*favListHeight*favListStartPos) + 'px');
        },100);
    }
}

function clickNext()
{
    if (favListEndPos < user_fav_lists.length)
    {
        favListStartPos = favListStartPos + 1;
        favListEndPos = favListEndPos + 1;
        refreshListsPos(-1*favListHeight);
        if (favListStartPos > 0)
        {
            $('prelist').innerHTML = "<img src='ico/up.png' />";
        }
        if (favListEndPos == user_fav_lists.length)
        {
            $('nextlist').innerHTML = "<img src='ico/over.png' />";
        }
        setTimeout(function() {
            $("lists_content").set('tween', {duration: 200});
            $("lists_content").tween("top", (-1*favListHeight*favListStartPos) + 'px');
        },100);
    }
}
function refreshListsPos(loan)
{
    for (var i = 0; i < user_fav_lists.length; ++i)
    {
        var name = "list" + i;
        favListLefts[i] = $j('#'+name).offset().left;
        favListTops[i] = $j('#'+name).offset().top + loan;
        favListRights[i] = $j('#'+name).offset().left + favListWidth;
        favListBottoms[i] = $j('#'+name).offset().top + loan + favListHeight;
    }
}

function clickFavType(e)
{
    if (clickDelete)
    {
        return;
    }
    if (pre_user_fav_pos != user_fav_pos)
    {
        favListClickTime = 1;
    }
    else
    {
        favListClickTime++;
    }
    if (user_fav_pos + 1 == user_fav_lists.length)
    {
        pre_user_fav_pos = user_fav_pos;
        tempfavType = user_fav_lists[user_fav_pos];
        tempfavListSelectPos = user_fav_pos;
        clickFavListOneTime();
        return;
    }
    if (favListClickTime == 1)
    {
        if (favListClickTimer != -1)
        {
            clearTimeout(favListClickTimer);
        }
        pre_user_fav_pos = user_fav_pos;
        tempfavType = user_fav_lists[user_fav_pos];
        tempfavListSelectPos = user_fav_pos;
        favListClickTimer = setTimeout(function(){clickFavListOneTime();}, 500);
    }
    else
    {
        dbclickRename();
    }
}

function dbclickRename()
{
    clearTimeout(favListClickTimer);
    promptNewOrRenameList('renameFavList()', '更改列表名');
    favListClickTime = 0;
}

function renameFavList()
{
    var oldfavType = user_fav_lists[user_fav_pos];
    var listname = $('newFavListName').value;
    if (listname.length == 0 || pleaseEnterListName)
    {
        myAlert('列表名当前为空！');
        return;
    }
    if (getStringBytesSize(listname) > 60)
    {
        myAlert('列表名必须小于15个中文或30个字符！');
        return;
    }
    if (listname == oldfavType)
    {
        myAlert('列表名无变动');
        return;
    }
    if (listname)
    {
    	var xmlhttp;
    	if (window.XMLHttpRequest)
      	{// code for IE7+, Firefox, Chrome, Opera, Safari
      		xmlhttp=new XMLHttpRequest();
      	}
    	else
      	{// code for IE6, IE5
      		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      	}
    	xmlhttp.onreadystatechange=function()
      	{
      		if (xmlhttp.readyState==4 && xmlhttp.status==200)
        	{
    			if (xmlhttp.responseText == "true")
    			{
                    user_fav_lists[user_fav_pos] = listname;
                    addUserFavList();
                    drawSelectedListWhenWatchFav();
                    myAlert('修改成功！');
    			}
    			else if (xmlhttp.responseText == 'LISTEXIST')
                {
                    myAlert('列表已存在') ;
                }
                else
    			{
                    myAlert('操作失败！');
    			}
        	}
      	}
    	xmlhttp.open("POST","renameFavList.php",true);
    	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    	xmlhttp.send("origin=" + oldfavType + "&changeto=" + listname);
    }
}

function clickFavListOneTime()
{
    favListClickTimer = -1;
    favType = tempfavType;
    favListSelectPos = tempfavListSelectPos;
    favClick();
    favListClickTime = 0;
}

function changeUserFavLists(type)
{
    //if type = 0, show user fav lists
    //if type = 1, select user fav lists to add a video
    if (type == 0)
    {
        $("favlists").setStyle("height", favListsHeight - 31);
        if (!ifShowPreList)
        {
            $('list'+(user_fav_lists.length-1)).setStyles({
                'border-bottom-width':'0px',
                'height':'24px'
            });
        }
        $("favlists").set('tween', {duration: 200});
        $("favlists").tween("opacity", favlistsOpacity);
    }
    else
    {
        $("favlists").setStyle("height", favListsHeight);
        if (!ifShowPreList)
        {
            $('list'+(user_fav_lists.length-1)).setStyles({
                'border-bottom-width':'1px',
                'height':'23px'
            });
        }
        $("favlists").set('tween', {duration: 200});
        $("favlists").tween("opacity", favlistsOpacity);
    }
}

function systemRecClick()
{
    $j('#popularity_list_watch').css('opacity', 0);
    $j('#personal_list_watch').css('opacity', 1);
    system_rec_type = 0;
    watchVideoType = 0;
    system_rec_click();
}

function system_rec_click()
{
    if (ifWatchMovie)
    {
        clearmovie();
    }
    watchType = 1;
    drawSelectedListWhenWatchFav();
    $j('#scanlist').empty();
    if (mw)
    {
        mw.stopLoading();
        mw = null;
    }
    var scanlist_content = new Element('div', {id:"scanlist_content", 'class':"unselectable"}).inject($('scanlist'), 'top');
    mf = new MooFlow($('scanlist_content'), {
	    startIndex: 0,
	    useSlider: true,
	    useAutoPlay: false,
	    useCaption: true,
	    useResize: false,
	    useMouseWheel: true,
	    useKeyInput: true
    });
    mf.loadData("getSystemRecInfo.php");
}

var repeat = 0;
function favclick()
{
    user_fav_pos = user_fav_lists.length - 1;
    favListSelectPos = user_fav_pos;
    favType = user_fav_lists[user_fav_pos];
    if (ifShowPreList)
    {
        favListEndPos = user_fav_lists.length;
        favListStartPos = favListEndPos - LargestListsNumber + 2;
        $('prelist').innerHTML = "<img src='ico/up.png' />";
        $('nextlist').innerHTML = "<img src='ico/over.png' />";
    }
    favClick();
}
function drawSelectedListWhenWatchFav()
{
    if (!favListLoadOver)
    {
        setTimeout(function() {drawSelectedListWhenWatchFav()},1000);
    }
    else
    {
        if (watchType == 4)
        {
            var listNumber = user_fav_lists.length;
            //check whether add the video into a list
            for (var i = 0; i < listNumber; ++i) 
            {
                //if add the video into a list
                if (i != favListSelectPos)
                {
                    $('list'+i).setStyle('background-color', favListNormalColor);
                    $j('#fav_list_watch'+i).css('opacity', 0);
                }
                else
                {
                    $j('#fav_list_watch'+favListSelectPos).css('opacity', 1);
                }
            }
        }
        else
        {
            if ($('list'+favListSelectPos))
            {
                $('list'+favListSelectPos).setStyle('background-color', favListNormalColor);
                $j('#fav_list_watch'+favListSelectPos).css('opacity', 0);
            }
        }
        if (ifShowPreList)
        {
            moveListContent();
        }
    }
}

function moveListContent()
{
    $('lists_content').setStyle('top', (-1*favListHeight*favListStartPos) + 'px');
    refreshListsPos(0);
}

function favClick()
{
    if (ifWatchMovie)
    {
        clearmovie();
    }
    watchType = 4;
    watchVideoType = 3;
    drawSelectedListWhenWatchFav();
    $j('#popularity_list_watch').css('opacity', 0);
    $j('#personal_list_watch').css('opacity', 0);

    if (mw)
    {
        mw.stopLoading();
    }
    $j('#scanlist').empty();
    if (mf)
    {
        mf = null;
    }
    var scanlist_content = new Element('div', {id:"scanlist_content", 'class':"unselectable"}).inject($('scanlist'), 'top');
    mw = new ImageWall($('scanlist_content'), {
	    startIndex: 0,
	    useSlider: true,
	    useAutoPlay: false,
	    useCaption: false,
	    useResize: false,
	    useMouseWheel: true,
	    useKeyInput: true
    });
    mw.loadData("getFavInfo.php", favType);
}

function user_email_mouse_over()
{
    $('setting').setStyle('visibility', 'visible');
}

function user_email_mouse_out()
{
    $('setting').setStyle('visibility', 'hidden');
}

function changePassword()
{
    originalPasswordState = false;
    newPasswordState = false;
	$("page_background_regist_filter").setStyle("visibility", "visible");
	$('page_background_regist_filter').set('opacity', 0.8);
	$("page_background_regist").setStyle("visibility", "visible");
	this.registPanel = new Element('div', {id:"changePassword"}).addClass('registPanelClass').inject($("page_background_regist"));
	this.registPanel.first = new Element('div', {id:"registPanel_first"}).addClass('registPanel_firstClass').inject(this.registPanel);
	this.registPanel.first.closebutton_background = new Element('div', {id:"registPanel_first_closebutton_background"}).addClass('registPanel_first_closebutton_backgroundClass').inject(this.registPanel.first);
	this.registPanel.first.closebutton_background.innerHTML = "<img src='ico/login_reg/login_close_normal.png' id='regist_close' onclick='closeChangePassword()' onmouseover='closeregistMouseOver(this)' onmouseout='closeregistMouseOut(this)' onmousedown='closeregistMouseDown(this)' onmouseup='closeregistMouseUp(this)' />";
	this.registPanel.second = new Element('div', {id:"registPanel_second"}).addClass('registPanel_234Class').inject(this.registPanel);
	this.registPanel.second.background = new Element('div', {id:"registPanel_second_background"}).addClass('registPanel_23_backgroundClass').inject(this.registPanel.second);
	this.registPanel.second.message = new Element('div', {id:'registPanel_second_message'}).addClass('registPanel_23_messageClass').inject(this.registPanel.second);
    if (browser.ie)
    {
	    this.registPanel.second.right = new Element('div', {id:'registPanel_second_right'}).addClass('registPanel_23_rightClass').inject(this.registPanel.second.background);
	    this.registPanel.second.right.innerHTML = "<input spellcheck='false' id='originalPassword' class='emailIEInput' type='text' value='原密码' onclick='originalPasswordClick(this)' onblur='originalPasswordBlur(this)'  onfocus='originalPasswordClick(this)'/>";
    }
    else
    {
	    this.registPanel.second.right = new Element('div').addClass('registPanel_23_rightClass').inject(this.registPanel.second.background);
	    this.registPanel.second.right.innerHTML = "<input spellcheck='false' id='originalPassword' class='emailInput' type='text' value='原密码' onclick='originalPasswordClick(this)' onblur='originalPasswordBlur(this)'  onfocus='originalPasswordClick(this)'/>";
    }
	this.registPanel.third = new Element('div', {id:"registPanel_third"}).addClass('registPanel_234Class').inject(this.registPanel);
	this.registPanel.third.background = new Element('div', {id:"registPanel_third_background"}).addClass('registPanel_23_backgroundClass').inject(this.registPanel.third);
    if (browser.ie)
    {
	    this.registPanel.third.right = new Element('div', {id:'registPanel_third_right'}).addClass('registPanel_23_rightClass').inject(this.registPanel.third.background);
	    this.registPanel.third.right.innerHTML = "<input spellcheck='false' id='newPassword' class='emailIEInput' type='text' value='新密码' onclick='newPasswordClick(this)' onblur='changePasswordBlur(this)' onfocus='newPasswordClick(this)' />";
    }
    else
    {
	    this.registPanel.third.right = new Element('div').addClass('registPanel_23_rightClass').inject(this.registPanel.third.background);
	    this.registPanel.third.right.innerHTML = "<input spellcheck='false' id='newPassword' class='emailInput' type='text' value='新密码' onclick='newPasswordClick(this)' onblur='changePasswordBlur(this)' onfocus='newPasswordClick(this)'/>";
    }
	this.registPanel.third.message = new Element('div', {id:'registPanel_third_message'}).addClass('registPanel_23_messageClass').inject(this.registPanel.third);
	this.registPanel.forth = new Element('div', {id:"registPanel_forth"}).addClass('registPanel_234Class').inject(this.registPanel);
	this.registPanel.forth.innerHTML = "<div id='registPanel_forth_button' class='registPanel_forth_buttonClass' onmouseover='registButtonMouseOver(this)' onmouseout='registButtonMouseOut(this)' onmousedown='registButtonMouseDown(this)' onmouseup='registButtonMouseUp(this)' onclick='changePasswordClick()'><div style='position:relative; top:10px'><span class='registButtonClass'>修改</span></div></div>";
}

function changePasswordClick()
{
    if ($j('#originalPassword').attr('type') != 'password' || $j('#originalPassword').val() == "")
    {
		$('registPanel_second_message').innerHTML = "<span class='messageclass' style='color:#F00'>原密码不能为空</span>";
        originalPasswordState = false;
    }
    if ($j('#newPassword').attr('type') != 'password')
    {
		$('registPanel_third_message').innerHTML = "<span class='messageclass' style='color:#F00'>新密码不能为空</span>";
        newPasswordState = false;
    }
    changePasswordBlur($('newPassword'));
    originalPasswordBlur($('originalPassword'));
    if (originalPasswordState && newPasswordState)
    {
        changePasswordToServer($j('#originalPassword').val(), $j('#newPassword').val());
    }
}

function changePasswordToServer(originalPass, newPass)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
            if (xmlhttp.responseText == 'true')
            {
                myAlert("密码修改成功");
            }
            else if (xmlhttp.responseText == 'WRONGPASS')
            {
                myAlert("密码错误");
            }
    	}
  	}
	xmlhttp.open("POST","changePassword.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send("originalPass=" + originalPass + "&newPass=" + newPass);

}

function originalPasswordBlur(o)
{
	if (o.value.length == 0 || $j('#originalPassword').attr('type') != 'password')
	{
		$('registPanel_second_message').innerHTML = "<span class='messageclass' style='color:#F00'>密码长度不能为空</span>";
        originalPasswordState = false;
	}
    else
    {
		$('registPanel_second_message').innerHTML = "<span class='messageclass' style='color:#F00'></span>";
        originalPasswordState = true;
    }
}

function changePasswordBlur(o)
{
	if (o.value.length > 5 && o.value.length < 21)
	{
		$('registPanel_third_message').innerHTML = "<span class='messageclass' style='color:#090'>密码有效</span>";
        newPasswordState = true;
	}
	else
	{
		$('registPanel_third_message').innerHTML = "<span class='messageclass' style='color:#F00'>密码长度应为6-20</span>";
        newPasswordState = false;
	}
}

function originalPasswordClick(o)
{
	o.value = "";
    if ($j('#originalPassword').attr('type') != 'password')
    {
        if (browser.ie)
        {
    	    $('registPanel_second_right').innerHTML = "<input id='originalPassword' type='password' class='emailIEInput'  onclick='originalPasswordClick(this) onblur='originalPasswordBlur(this)' onfocus='originalPasswordClick(this)'/>";
            $('originalPassword').setStyle('color', '#000');
            $('originalPassword').focus();
        }
        else
        {
    	    o.setStyle('color', '#000');
    	    o.set('type', 'password');
        }
    }
}

function newPasswordClick(o)
{
	o.value = "";
    if ($j('#newPassword').attr('type') != 'password')
    {
        if (browser.ie)
        {
    	    $('registPanel_third_right').innerHTML = "<input id='newPassword' type='password' class='emailIEInput' onclick='newPasswordClick(this)' onblur='changePasswordBlur(this)' onfocus='newPasswordClick(this)'/>";
            $('newPassword').setStyle('color', '#000');
            $('newPassword').focus();
        }
        else
        {
    	    o.setStyle('color', '#000');
    	    o.set('type', 'password');
        }
    }
	$('registPanel_third_message').innerHTML = "<span class='messageclass' style='color:#999'>密码由6-20位半角字符（字母、数字、符号）组成</span>";
}

function closeChangePassword()
{
    $('changePassword').destroy();
	$("page_background_regist_filter").setStyle("visibility", "hidden");
	$("page_background_regist").setStyle("visibility", "hidden");
}

function settingover(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/reg_button_mouseon.png')";
	else
		o.setStyle('background-image', 'url(ico/reg_button_mouseon.png)');	
    //$j('#settingword').css('color', 'rgb(242, 242, 242)');
}

function settingup(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/reg_button_mouseon.png')";
	else
		o.setStyle('background-image', 'url(ico/reg_button_mouseon.png)');	
}

function settingdown(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/reg_button_click.png')";
	else
		o.setStyle('background-image', 'url(ico/reg_button_click.png)');	
}

function settingout(o)
{
	if (browser.ie)
		o.style.backgroundImage = "";
	else
		o.setStyle('background-image', '');	
    //$j('#settingword').css('color', '#000');
}

function logoutover(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/reg_button_mouseon.png')";
	else
		o.setStyle('background-image', 'url(ico/reg_button_mouseon.png)');	
    //$j('#logoutword').css('color', 'rgb(242, 242, 242)');
}

function logoutup(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/reg_button_mouseon.png')";
	else
		o.setStyle('background-image', 'url(ico/reg_button_mouseon.png)');	
}

function logoutdown(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/reg_button_click.png')";
	else
		o.setStyle('background-image', 'url(ico/reg_button_click.png)');	
}

function logoutout(o)
{
	if (browser.ie)
		o.style.backgroundImage = "";
	else
		o.setStyle('background-image', '');	
    //$j('#logoutword').css('color', '#000');
}

function logoutclick()
{
	if (ifWatchMovie)
	{
		clearmovie();
	}
	window.location.href="logout.php";	
}

function settingclick()
{
    self.location='setting.php';
}

function RemoveMovieMouseOver(o)
{
	o.src = "ico/remove_mouseon.png";
}

function RemoveMovieMouseDown(o)
{
	o.src = "ico/remove_click.png";
}

function RemoveMovieMouseUp(o)
{
	o.src = "ico/remove_mouseon.png";
}

function RemoveMovieMouseOut(o)
{
	o.src = "ico/remove.png";
}

function watchmovie(href, title, playlink)
{
    ifWatchMovie = true;
    videoTitle = title;
    videoID = href;
    videoPlayLink = playlink;
    watchVideoStart = new Date();
    watchVideoId = href;
    $('playwindow_background_center').setStyle('z-index', 99);
    $('playwindow_background_center').set('opacity', 0.8);
    $('playwindow_scanlist_center').setStyle('z-index', 100);
    $('playwindow_background').setStyle('z-index', 101);
    $('removemovie').setStyle('visibility', 'visible');
    this.player = new Element('div', {id:"player"}).inject($('playwindow_background'), 'top');
    this.player.setStyles({
        'position':'relative',
        'z-index':'120',
        'width':'0px',
        'height':'498px',
        'background-color':'#FFF',
        'z-index':'150'
    });
    $("player").set('tween', {duration: 300});
    $("player").tween("width", 610);
    this.player.cover = new Element('div', {id:"player_cover"}).inject($('playwindow_background'), 'top');
    this.player.cover.setStyles({
        'width':'610px',
        'height':'100px',
        'left':'0px',
        'position':'absolute',
        'z-index':'150'
    });
    this.player.cover.content = new Element('div', {id:'player_cover_content'}).inject(this.player.cover, 'top');
    this.player.cover.content.setStyles({
        'width':'610px',
        'height':'0px',
        'left':'0px',
        'cursor':'url(ico/hand-open.cur),pointer',
        'background-image':'url(ico/title_bg.png)',
        'background-repeat':'repeat',
        'vertical-align':'middle',
        'overflow':'hidden'
    });

    this.player.cover.renren = new Element('img', {id:'renren_share'}).inject($('playwindow_background'), 'top');
	this.player.cover.renren.src = "ico/share/renren.png";
    this.player.cover.renren.setStyles({
        'position':'absolute',
        'top':'472px',
        'left':'150px',
        'cursor':'pointer',
        'opacity':'0',
        'z-index':'150'
    });
    $j('#renren_share').attr('title', '分享到人人');
    $j('#renren_share').click(renrenShare);

    this.player.cover.weibo = new Element('img', {id:'weibo_share'}).inject($('playwindow_background'), 'top');
	this.player.cover.weibo.src = "ico/share/weibo.gif";
    this.player.cover.weibo.setStyles({
        'position':'absolute',
        'top':'472px',
        'left':'180px',
        'cursor':'pointer',
        'opacity':'0',
        'z-index':'150'
    });
    $j('#weibo_share').attr('title', '分享到新浪微博');
    $j('#weibo_share').click(weiboShare);

    this.player.cover.tencentweibo = new Element('img', {id:'tencentweibo_share'}).inject($('playwindow_background'), 'top');
	this.player.cover.tencentweibo.src = "ico/share/tencentweibo.png";
    this.player.cover.tencentweibo.setStyles({
        'position':'absolute',
        'top':'472px',
        'left':'210px',
        'cursor':'pointer',
        'opacity':'0',
        'z-index':'150'
    });
    $j('#tencentweibo_share').attr('title', '分享到腾讯微博');
    $j('#tencentweibo_share').click(tencentweiboShare);

    this.player.cover.qqkongjian = new Element('img', {id:'qqkongjian_share'}).inject($('playwindow_background'), 'top');
	this.player.cover.qqkongjian.src = "ico/share/qqkongjian.png";
    this.player.cover.qqkongjian.setStyles({
        'position':'absolute',
        'top':'472px',
        'left':'240px',
        'cursor':'pointer',
        'opacity':'0',
        'z-index':'150'
    });
    $j('#qqkongjian_share').attr('title', '分享到qq空间');
    $j('#qqkongjian_share').click(qqkongjianShare);

    setTimeout(function() {embedswf(href)},250);


    $('player').addClass('unselectable');
    $('player_cover').addClass('unselectable');
    $('player_cover_content').addClass('unselectable');
    $j('#player').attr('unselectable', 'on');
    $j('#player_cover').attr('unselectable', 'on');
    $j('#player_cover_content').attr('unselectable', 'on');
    playerCoverContentLeft = $j('#player_cover_content').offset().left;
    playerCoverContentTop = $j('#player_cover_content').offset().top;
    playerCoverContentRight = playerCoverContentLeft + 610;
    playerCoverContentBottom = playerCoverContentTop + titleHeight;
    playerCoverBottom = playerCoverContentTop + 100;
}

function showShare()
{
    if ($("renren_share"))
    {
        $("renren_share").set('tween', {duration: 500});
        $("renren_share").tween("opacity", 1);
    }
    if ($("weibo_share"))
    {
        $("weibo_share").set('tween', {duration: 500});
        $("weibo_share").tween("opacity", 1);
    }
    if ($("tencentweibo_share"))
    {
        $("tencentweibo_share").set('tween', {duration: 500});
        $("tencentweibo_share").tween("opacity", 1);
    }
    if ($("qqkongjian_share"))
    {
        $("qqkongjian_share").set('tween', {duration: 500});
        $("qqkongjian_share").tween("opacity", 1);
    }
}

function renrenShare()
{
    window.open ('http://share.renren.com/share/buttonshare.do?link=' + videoPlayLink,'newwindow','height=500,width=500,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
}

function weiboShare()
{
    window.open('http://v.t.sina.com.cn/share/share.php?appkey=2684493555&url=' + videoPlayLink + '&title=' + videoTitle + '&ralateUid=1642904381&source=%E4%BC%98%E9%85%B7%E7%BD%91&sourceUrl=http%3A%2F%2Fwww.youku.com%2F&content=utf8', 'newwindow','height=500,width=500,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
}

function tencentweiboShare()
{
    window.open('http://share.v.t.qq.com/index.php?c=share&a=index&title=' + videoTitle + '&url=' + videoPlayLink + '&appkey=e7ad0b0199994bda85ecc0a44ce9915f&site=www.youku.com&assname=youku2010', 'newwindow','height=500,width=500,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
}

function qqkongjianShare()
{
    window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + videoPlayLink, 'newwindow','height=500,width=500,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
}

function playerCoverContentMouseover(e)
{
    //the dragging action ends within player_cover_content
    if (drag)
    {
        return;
    }
	drag = true;
    if (move)
    {
        return;
    }
	if (browser.ie)
	    $j('#player_cover_content').css("background-image", "url('ico/title_bg_mouseon.png')");
	else
		$j('#player_cover_content').css('background-image', 'url(ico/title_bg_mouseon.png)');
}

function playerCoverContentMouseout(e)
{
	drag = false;
    if (move)
    {
        return;
    }
	if (browser.ie)
	    $j('#player_cover_content').css("background-image", "url('ico/title_bg.png')");
	else
		$j('#player_cover_content').css('background-image', 'url(ico/title_bg.png)');
}

function playerCoverIn(e)
{
    if (move || drag)
    {
        return;
    }
	if (browser.ie)
	    $j('#player_cover_content').css("background-image", "url('ico/title_bg.png')");
	else
		$j('#player_cover_content').css('background-image', 'url(ico/title_bg.png)');
    $("player_cover_content").set('tween', {duration: 500});
    $("player_cover_content").tween("height", titleHeight);
    if ($('title_div'))
    {
        return;
    }
    $('player_cover_content').innerHTML = normalizeTitle(videoTitle, titleWordsHeight);
    videoTitleLength = getTitleLength(videoTitle);
    if (videoTitleLength < 500)
    {
        $j('#title_div').css('visibility', 'visible');
    }
    else
    {
        $('player_cover_content').innerHTML = dynamicTitle(videoTitle, videoTitleLength, titleWordsHeight);
        setTimeout(function() { titleMove(); },500);
    }
}

function playerCoverOut(e)
{
    if (move)
    {
        drag = false;
        return;
    }
    $j('#title_div').remove();
    if ($('player_cover_content'))
    {
        $("player_cover_content").set('tween', {duration: 500}); $("player_cover_content").tween("height", 0);
    }
}

function embedswf(href)
{
	var flashvars = {playMovie:"true"};
	var params = {wmode:'opaque', quality:"high", allowScriptAccess:"always", allowfullscreen:"true"};
	var attributes = {id: "videoplayer"};
	swfobject.embedSWF("http://static.youku.com/v1.0.0097/qplayer.swf?&VideoIDS=" + href + "=&isAutoPlay=true&#=/v.swf", "player", "610", "498", "9.0.0", false, flashvars, params, attributes);
    setTimeout(function() { showShare(); },1000);
}

function mouseDown(e) {
    if (window.event && !browser.ie)
    {
        window_event = window.event;
    }
    else
    {
        window_event = e;
    }
    //means watching video and mouse in player_cover_content
    if (drag) {
        move = true;
        if($j('#player_cover_content'))
        {
            showDragImg(watch_movie_image_source);
            //dig the player_cover_content
    	    if (browser.ie)
    		    $j('#player_cover_content').css("background-image", "url('ico/title_bg_clickon.png')");
    	    else
    		    $j('#player_cover_content').css('background-image', 'url(ico/title_bg_clickon.png)');
            if ($('title'))
            {
                $j('#title').attr('color', 'grey');
            }
            if ($('title1'))
            {
                $j('#title1').attr('color', 'grey');
            }
            if ($('title2'))
            {
                $j('#title2').attr('color', 'grey');
            }
        }
    }
}

function showDragImg(imgSource)
{
    var content_position = $j('#scanlist_top').offset();
    var left = window_event.pageX - content_position.left;
    var up = window_event.pageY - content_position.top;
    left = left - 37;
    up = up - 13;
    this.dragimg = new Element('img', {id:'dragimg'}).inject($('scanlist_top'));
    $j('#dragimg').attr('src', imgSource);
    $j('#dragimg').attr('unselectable', 'on');
    //this.dragimg.src = 'ico/setting.png';
    $('dragimg').setStyles({
    	'position':'absolute',
        'height':'48px',
        'opacity':'0.6',
        'width':'64px',
    	'top':up + 'px',
    	'left':left + 'px'
    });
    $('dragimg').addClass('unselectable');
    dragObj = $j('#dragimg');
    dragObj.css('cursor', "url('ico/hand-close.cur'), auto");
    clickleft = window_event.pageX - left;
    clicktop = window_event.pageY - up;
    document.body.style.cursor = ('cursor', "url('ico/hand-close.cur'), auto");
}

function mouseStop(e) {
	//forbid the mouse dragging on the page
    return false;
}

function mouseMove(e) {
    if (window.event && !browser.ie)
    {
        window_event = window.event;
    }
    else
    {
        window_event = e;
    }
    mouseX = window_event.pageX;
    mouseY = window_event.pageY;
    //if dragging the video
    if (move) {
        if (window_event.pageX >= dragActivateAreaLeft && window_event.pageX <= dragActivateAreaRight)
        {
            dragObj.css('left', window_event.pageX - clickleft);
        }
        if (window_event.pageY >= dragActivateAreaTop && window_event.pageY <= dragActivateAreaBottom)
        {
            dragObj.css('top', window_event.pageY - clicktop);
        }
        if (window_event.pageX >= favAreaLeft && window_event.pageX <= favAreaRight && window_event.pageY >= favAreaTop && window_event.pageY <= favAreaBottom)
        {
	        if (browser.ie)
		        $j('#favor').css("background-image", "url('ico/button_mouseon.png')");
	        else
		        $j('#favor').css('background-image', 'url(ico/button_mouseon.png)');
            if (!$("list0"))
            {
                addUserFavList();
            }
            if ($j('#favlists').css('opacity') == 0)
            {
                changeUserFavLists(1);
            }
        }
        if ($j('#favlists').css('opacity') > 0)
        {
            var listNumber = user_fav_lists.length;
            for (i = favListStartPos; i < listNumber && i < favListEndPos; ++i) 
            {
                if (window_event.pageX >= favListLefts[i] && window_event.pageX <= favListRights[i] && window_event.pageY > favListTops[i] && window_event.pageY <= favListBottoms[i])
                {
                    $('list'+i).setStyle('background-color', favListScanColor);
                }
                else{
                    $('list'+i).setStyle('background-color', favListNormalColor);
                }
            }
            if (ifShowPreList && window_event.pageX >= preListLeft && window_event.pageX <= preListRight && window_event.pageY > preListTop && window_event.pageY < preListBottom)
            {
                $('prelist').setStyle('background-color', favListScanColor);
                if (!ifWantPreFavList)
                {
                    preFavTimeOut = setInterval(function(){checkPreFav()}, 300);
                }
                ifWantPreFavList = true;
            }
            else if (ifShowPreList)
            {
                $('prelist').setStyle('background-color', favListNormalColor);
                ifWantPreFavList = false;
                clearInterval(preFavTimeOut);
            }
            if (ifShowPreList && window_event.pageX >= nextListLeft && window_event.pageX <= nextListRight && window_event.pageY > nextListTop && window_event.pageY < nextListBottom)
            {
                $('nextlist').setStyle('background-color', favListScanColor);
                if (!ifWantNextFavList)
                {
                    nextFavTimeOut = setInterval(function(){checkNextFav()}, 300);
                }
                ifWantNextFavList = true;
            }
            else if (ifShowPreList)
            {
                $('nextlist').setStyle('background-color', favListNormalColor);
                ifWantNextFavList = false;
                clearInterval(nextFavTimeOut);
            }
            if ($('createNewList'))
            {
                if (window_event.pageX >= newFavListLeft && window_event.pageX <= newFavListRight && window_event.pageY > newFavListTop && window_event.pageY <= newFavListBottom)
                {
                    $('createNewList').setStyle('background-color', favListScanColor);
                }
                else
                {
                    $('createNewList').setStyle('background-color', favListNormalColor);
                }
            }
        }
    }
    if (!move && $j('#favlists').css('opacity') > 0)
    {
        var listNumber = user_fav_lists.length;
        for (i = favListStartPos; i < listNumber && i < favListEndPos; ++i) 
        {
            if (window_event.pageX >= favListLefts[i] && window_event.pageX <= favListRights[i] && window_event.pageY > favListTops[i] && window_event.pageY <= favListBottoms[i])
            {
                $('list'+i).setStyle('background-color', favListScanColor);
                if (i != user_fav_lists.length - 1)
                {
                    if (browser.ie && $('emailActivate'))
                    {
                        $('fav_list_delete'+i).setStyle('opacity', 0);
                    }
                    else
                    {
                        $('fav_list_delete'+i).setStyle('opacity', 1);
                    }
                }
                user_fav_pos = i;
            }
            else{
                $('list'+i).setStyle('background-color', favListNormalColor);
                if (i != user_fav_lists.length - 1)
                {
                    $('fav_list_delete'+i).setStyle('opacity', 0);
                }
            }
        }
        if (ifShowPreList && window_event.pageX >= preListLeft && window_event.pageX <= preListRight && window_event.pageY > preListTop && window_event.pageY < preListBottom)
        {
            $('prelist').setStyle('background-color', favListScanColor);
            if (!ifWantPreFavList)
            {
                preFavTimeOut = setInterval(function(){checkPreFav()}, 300);
            }
            ifWantPreFavList = true;
        }
        else if (ifShowPreList)
        {
            $('prelist').setStyle('background-color', favListNormalColor);
            ifWantPreFavList = false;
            clearInterval(preFavTimeOut);
        }
        if (ifShowPreList && window_event.pageX >= nextListLeft && window_event.pageX <= nextListRight && window_event.pageY > nextListTop && window_event.pageY < nextListBottom)
        {
            $('nextlist').setStyle('background-color', favListScanColor);
            if (!ifWantNextFavList)
            {
                nextFavTimeOut = setInterval(function(){checkNextFav()}, 300);
            }
            ifWantNextFavList = true;
        }
        else if (ifShowPreList)
        {
            $('nextlist').setStyle('background-color', favListNormalColor);
            ifWantNextFavList = false;
            clearInterval(nextFavTimeOut);
        }
        if ($('createNewList'))
        {
            if (window_event.pageX >= newFavListLeft && window_event.pageX <= newFavListRight && window_event.pageY > newFavListTop && window_event.pageY <= newFavListBottom)
            {
                $('createNewList').setStyle('background-color', favListScanColor);
            }
            else
            {
                $('createNewList').setStyle('background-color', favListNormalColor);
            }
        }
    }
    //if watch video but not dragging the video, if the mouse is on the favlists and title, the title will not change
    if (ifWatchMovie && !move)
    { 
        var inFavList = checkInFavList();
        if (!inFavList && window_event.pageX >= playerCoverContentLeft && window_event.pageX <= playerCoverContentRight && window_event.pageY >= playerCoverContentTop && window_event.pageY <= playerCoverBottom)
        {
            playerCoverIn(e);
            if (window_event.pageY <= playerCoverContentBottom)
            {
                playerCoverContentMouseover(e);
            }
            else
            {
                playerCoverContentMouseout(e)
            }
        }
        else
        {
            playerCoverContentMouseout(e)
            playerCoverOut(e);
        }
    }
}

function checkPreFav()
{
    if (ifWantPreFavList)
    {
        clickPre();
    }
}

function checkNextFav()
{
    if (ifWantNextFavList)
    {
        clickNext();
    }
}

function checkInFavList()
{
    var inFavList = false;
    if ($j('#favlists').css('opacity') > 0)
    {
        var listNumber = user_fav_lists.length;
        //check whether add the video into a list
        for (i = favListStartPos; i < listNumber && i < favListEndPos; ++i) 
        {
            //if add the video into a list
            if ($j("#list"+i).css('background-color') == favListScanColor)
            {
                inFavList = true;
                break;
            }
        }
        if (ifShowPreList && ($j('#prelist').css('background-color') == favListScanColor || $j('#nextlist').css('background-color') == favListScanColor) || $j('#createNewList').css('background-color') == favListScanColor)
        {
            inFavList = true;
        }
    }
    return inFavList;
}

function mouseUp(e) {
    if (window.event && !browser.ie)
    {
        window_event = window.event;
    }
    else
    {
        window_event = e;
    }
    if (!ifWatchMovie && !move)
    {
        return;
    }
    if (move)
    {
        if (window_event.pageX < playerCoverContentLeft || window_event.pageX > playerCoverContentRight || window_event.pageY < playerCoverContentTop || window_event.pageY > playerCoverBottom)
        {
            $j('#title_div').remove();
        }
        deleteDragImg();
    }
    if (window_event.pageX >= playerCoverContentLeft && window_event.pageX <= playerCoverContentRight && window_event.pageY >= playerCoverContentTop && window_event.pageY <= playerCoverBottom)
    {
	    if (browser.ie)
		    $j('#player_cover_content').css("background-image", "url('ico/title_bg.png')");
	    else
		    $j('#player_cover_content').css('background-image', 'url(ico/title_bg.png)');
        if ($('title'))
        {
            $j('#title').attr('color', 'black');
        }
        if ($('title1'))
        {
            $j('#title1').attr('color', 'black');
        }
        if ($('title2'))
        {
            $j('#title2').attr('color', 'black');
        }
    }
    else
    {
        playerCoverContentMouseout(e)
        playerCoverOut(e);
    }
}

function deleteDragImg()
{
    move = false;
    //add to fav
    if (window_event.pageX >= favAreaLeft && window_event.pageX <= favAreaRight && window_event.pageY >= favAreaTop && window_event.pageY <= favAreaBottom)
    {
        insertIntoList(user_fav_lists.length - 1);
    }
	$j('#dragimg').remove();
    document.body.style.cursor = ('cursor', "");
    if ($j('#favlists').css('opacity') > 0)
    {
        $("favlists").set('tween', {duration: 200});
        $("favlists").tween("opacity", 0);
		$j('#favor').css("background-image", "");
        var listNumber = user_fav_lists.length;
        //check whether add the video into a list
        for (i = favListStartPos; i < listNumber && i < favListEndPos; ++i) 
        {
            //if add the video into a list
            if ($j("#list"+i).css('background-color') == favListScanColor || $j("#list"+i).css('background-color') == favListScanColorIE)
            {
                $('list'+i).setStyle('background-color', favListNormalColor);
                if (i != user_fav_lists.length - 1)
                {
                    $('fav_list_delete'+i).setStyle('opacity', 0);
                }
                insertIntoList(i);
                return;
            }
        }
        if ($j('#createNewList').css('background-color') == favListScanColor || $j('#createNewList').css('background-color') == favListScanColorIE)
        {
            $('createNewList').setStyle('background-color', favListNormalColor);
            //setTimeout(function() {promptNewList();},1000);
            promptNewOrRenameList('addNewFavConfirmClick()', '请输入列表名');
        }
    }
}

function insertIntoList(listPos)
{
    var list = user_fav_lists[listPos];
    addToFav(list, 0);
}

function promptNewOrRenameList(onclick, message)
{
    pleaseEnterListName = true;
	$("page_background_regist_filter").setStyle("visibility", "visible");
	$('page_background_regist_filter').set('opacity', 0.8);
	$("page_background_regist").setStyle("visibility", "visible");
    this.emailActivate = new Element('div', {id:"emailActivate"}).addClass('emailActivateClass').inject($("page_background_regist"));
    this.emailActivate.first = new Element('div', {id:"registPanel_first"}).addClass('registPanel_firstClass').inject(this.emailActivate);
    this.emailActivate.first.closebutton_background = new Element('div', {id:"registPanel_first_closebutton_background"}).addClass('registPanel_first_closebutton_backgroundClass').inject(this.emailActivate.first);
    this.emailActivate.first.closebutton_background.innerHTML = "<img src='ico/login_reg/login_close_normal.png' id='regist_close' onclick='clearregist(this)' onmouseover='closeregistMouseOver(this)' onmouseout='closeregistMouseOut(this)' onmousedown='closeregistMouseDown(this)' onmouseup='closeregistMouseUp(this)' />";
    this.emailActivate.logo = new Element('div').addClass('changePass_logoClass').inject($(this.emailActivate));
    this.emailActivate.logo.innerHTML = "<img src='ico/logo4.png' />";
    this.emailActivate.third = new Element('div', {id:'emailActivate_third'}).addClass('changePass_thirdClass').inject($(this.emailActivate));
    this.emailActivate.third.center = new Element('div', {id:'changePass_input'}).addClass('changePass_input').inject(this.emailActivate.third);
    if (browser.ie)
    {
	    this.emailActivate.third.center.innerHTML = "<input spellcheck='false' id='newFavListName' class='emailIEInput' type='text' value='" + message + "' onclick='addNewFavInputClick(this)' onkeypress='addNewFavInputKeyPress(event, this)' />";
    }
    else
    {
	    this.emailActivate.third.center.innerHTML = "<input spellcheck='false' id='newFavListName' class='emailInput' type='text' value='" + message + "' onclick='addNewFavInputClick(this)' onkeypress='addNewFavInputKeyPress(event, this)' />";
    }
    this.emailActivate.third.message = new Element('div', {id:'changePass_message'}).inject(this.emailActivate.third);
	this.emailActivate.forth = new Element('div', {id:"changePass_forth"}).inject(this.emailActivate);
	this.emailActivate.forth.innerHTML = "<div id='changePassConfirm' class='changePassConfirmClass' onmouseover='loginButtonMouseOver(this)' onmouseout='loginButtonMouseOut(this)' onmousedown='loginButtonMouseDown(this)' onmouseup='loginButtonMouseUp(this)' onclick='" + onclick + "'><div style='position:relative; top:10px'>确定</div></div>";
}
function myConfirm(message, handlefunction, listname)
{
    confirmListName = listname;
	$("page_background_regist_filter").setStyle("visibility", "visible");
	$('page_background_regist_filter').set('opacity', 0.8);
	$("page_background_regist").setStyle("visibility", "visible");
    this.emailActivate = new Element('div', {id:"emailActivate"}).addClass('emailActivateClass').inject($("page_background_regist"));
    this.emailActivate.first = new Element('div', {id:"registPanel_first"}).addClass('registPanel_firstClass').inject(this.emailActivate);
    this.emailActivate.first.closebutton_background = new Element('div', {id:"registPanel_first_closebutton_background"}).addClass('registPanel_first_closebutton_backgroundClass').inject(this.emailActivate.first);
    this.emailActivate.first.closebutton_background.innerHTML = "<img src='ico/login_reg/login_close_normal.png' id='regist_close' onclick='clearregist(this)' onmouseover='closeregistMouseOver(this)' onmouseout='closeregistMouseOut(this)' onmousedown='closeregistMouseDown(this)' onmouseup='closeregistMouseUp(this)' />";
    this.emailActivate.logo = new Element('div').addClass('changePass_logoClass').inject($(this.emailActivate));
    this.emailActivate.logo.innerHTML = "<img src='ico/logo4.png' />";
    this.emailActivate.second = new Element('div', {id:'emailActivate_second'}).addClass('warningClass').inject($(this.emailActivate));
    this.emailActivate.second.content = new Element('div', {id:'confirm_message'}).addClass('confirmMessageClass').inject($(this.emailActivate.second));
    var newmessage = "";
    var i = 0;
    //the title[i] is the i'th character (no mater english or chinese) of title
    while (i < message.length)
    {
        var t = message[i];
        newmessage += t;
        if (i % 15 == 14)
        {
            newmessage += '</br>';
        }
        i = i + 1;
    }
    this.emailActivate.second.content.innerHTML = "<span style='color:#999'>" + newmessage + "</span>";
    this.emailActivate.third = new Element('div', {id:'emailActivate_third'}).addClass('confirmThirdClass').inject($(this.emailActivate));
	this.emailActivate.third.innerHTML = "<div class='deleteFavListConfirmClass' onmouseover='loginButtonMouseOver(this)' onmouseout='loginButtonMouseOut(this)' onmousedown='loginButtonMouseDown(this)' onmouseup='loginButtonMouseUp(this)' onclick='" + handlefunction + "'><div style='position:relative; top:10px'>确定</div></div>";
}

function deleteFavList()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if (xmlhttp.responseText == "true")
			{
                list = [];
                var deletePos;
                for (i = 0; i < user_fav_lists.length; ++i)
                {
                    if (user_fav_lists[i] != confirmListName)
                    {
                        list.push(user_fav_lists[i]);
                    }
                    else
                    {
                        deletePos = i;
                    }
                }
                user_fav_lists = list;
                addUserFavList();
                if (watchType == 4)
                {
                    if (favListSelectPos == deletePos)
                    {
                        favListSelectPos = user_fav_lists.length - 1;
                        favType = user_fav_lists[favListSelectPos];
                        favClick();
                    }
                    else if (favListSelectPos > deletePos)
                    {
                        favListSelectPos--;
                        drawSelectedListWhenWatchFav();
                    }
                    else
                    {
                        drawSelectedListWhenWatchFav();
                    }
                }
			}
    	}
  	}
	xmlhttp.open("POST","deleteFavList.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send("fav_type=" + confirmListName);
	if ($('regist_close'))
	{
		clearregist($('regist_close'));	
	}
}

function addNewFavInputClick(o)
{
    pleaseEnterListName = false;
	o.value = "";
    if (browser.ie)
    {
        o.style.color = '#000';
    }
    else
    {
	    o.setStyle('color', '#000');
    }
}


function addNewFavInputKeyPress(e, o)
{
	/*if (e.keyCode == 13)
	{
        addNewFavConfirmClick();
	}	*/
}

function addNewFavConfirmClick()
{
    var listname = $('newFavListName').value;
    if (listname.length == 0 || pleaseEnterListName)
    {
        myAlert('列表名当前为空！');
        return;
    }
    if (getStringBytesSize(listname) > 60)
    {
        myAlert('列表名必须小于15个中文或30个字符！');
        return;
    }
    if (listname)
    {
		clearregist($('regist_close'));	
        addToFav(listname, 1);
    }
}

function addToFav(list, newlist)
{
	if (browser.ie)
		$j('#favor').css("background-image", "");
	else
		$j('#favor').css('background-image', '');
    /*if (watchType == 4)
    {
        return;
    }*/
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if (xmlhttp.responseText == "true")
			{
                var plusone = new Element('img', {id:'plusone'}).inject($('scanlist_top'), 'top');
                $j('#plusone').attr('src', 'ico/plus1.png');
                $('plusone').setStyles({
            	    'position':'absolute',
            		'top':'-10px',
            		'left':'755px'
                });
                $('plusone').set('tween', {duration: plusOneFloat});
                $('plusone').tween("top", '-40px');
                setTimeout(function(){ 
                    $('plusone').set('tween', {duration: plusOneDisappear}); 
                    $('plusone').tween("opacity", 0); 
                    setTimeout(function(){$j('#plusone').remove(); },plusOneDisappear);
                },plusOneFloat);
                if (newlist == 1)
                {
                    user_fav_lists.splice(0, 0, list);
                    addUserFavList();
                    if (watchType == 4)
                    {
                        favListSelectPos++;
                        drawSelectedListWhenWatchFav();
                    }
                }
			}
			else if (xmlhttp.responseText == "LISTEXIST")
			{
                myAlert("该列表已存在!");
			}
    	}
  	}
	xmlhttp.open("POST","addFavor.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send("videoID=" + videoID + "&listname=" + list + "&newlist=" + newlist);
}

function resize()
{
    dragActivateAreaLeft = $j('#scanlist_top').offset().left + 40;
	dragActivateAreaTop = $j('#scanlist_top').offset().top - 20;
	dragActivateAreaRight = $j('#scanlist_bottom').width() + $j('#scanlist_bottom').offset().left - 40;
	dragActivateAreaBottom = $j('#scanlist_bottom').height() + $j('#scanlist_bottom').offset().top - 20;
    favAreaLeft = $j('#favor').offset().left;
    favAreaTop = $j('#favor').offset().top;
    favAreaRight = $j('#favor').width() + $j('#favor').offset().left;
    favAreaBottom = $j('#favor').height() + $j('#favor').offset().top;
    if ($('player_cover_content'))
    {
        playerCoverContentLeft = $j('#player_cover_content').offset().left;
        playerCoverContentTop = $j('#player_cover_content').offset().top;
        playerCoverContentRight = playerCoverContentLeft + 610;
        playerCoverContentBottom = playerCoverContentTop + titleHeight;
        playerCoverBottom = playerCoverContentTop + 100;
    }
    if ($('list1'))
    {
        refreshListsPos(0);
        newFavListTop = $j('#createNewList').offset().top;
        newFavListLeft = $j('#createNewList').offset().left;
        newFavListRight = $j('#createNewList').offset().left + favListWidth;
        newFavListBottom = $j('#createNewList').offset().top + favListHeight;
        if (ifShowPreList)
        {
            preListLeft = $j('#prelist').offset().left;
            preListTop = $j('#prelist').offset().top;
            preListRight = $j('#prelist').offset().left + favListWidth;
            preListBottom = $j('#prelist').offset().top + favListHeight;
            nextListLeft = $j('#nextlist').offset().left;
            nextListTop = $j('#nextlist').offset().top;
            nextListRight = $j('#nextlist').offset().left + favListWidth;
            nextListBottom = $j('#nextlist').offset().top + favListHeight;
        }
    }
    if (pageWidth() <= 1250)
    {
        $("page_background_regist_filter").setStyles({'width':'1250px'});
        $("page_background_regist").setStyles({'width':'1250px'});
    }
    else
    {
        $("page_background_regist_filter").setStyles({'width':'100%'});
        $("page_background_regist").setStyles({'width':'100%'});
    }
    if (pageHeight() <= 660)
    {
        $("page_background_regist_filter").setStyles({'height':'660px'});
        $("page_background_regist").setStyles({'height':'660px'});
    }
    else
    {
        $("page_background_regist_filter").setStyles({'height':'100%'});
        $("page_background_regist").setStyles({'height':'100%'});
    }
}

function titleMove()
{
    videoTitleLeft1 = Number($j('#title1').css('left'));
    videoTitleLeft2 = Number($j('#title2').css('left'));
    titleAni();
}

function titleAni()
{
    var time = videoTitleLength * 20;
    if ($("title1"))
    {
        $("title1").set('tween', {duration: time, transition: Fx.Transitions.linear});
        $("title1").tween("left", '-' + videoTitleLength + 'px');
        $("title2").set('tween', {duration: (time * (1 + 200 / (200 + videoTitleLength))), transition: Fx.Transitions.linear});
        $("title2").tween("left", '0px');
    }
}

function tutorialdown(o)
{
	if (browser.ie)
		o.style.backgroundImage = "url('ico/turorial_mouse_down.png')";
	else
		o.setStyle('background-image', 'url(ico/turorial_mouse_down.png)');	
}

function tutorialClick()
{
	$("page_background_regist_filter").setStyle("visibility", "visible");
	$('page_background_regist_filter').set('opacity', 0.8);
	$("page_background_regist").setStyle("visibility", "visible");
	new Element('div', {id:"tutorial_background"}).inject($("page_background_regist"));
    $('tutorial_background').innerHTML = '<img src="ico/tutorial.png" style="position:relative;width:1000px; height:563px;"/>';
	new Element('div', {id:"tutorial_close"}).inject($('tutorial_background'));
	$('tutorial_close').innerHTML = "<img src='ico/login_reg/login_close_normal.png' id='regist_close' onclick='clearregist(this)' onmouseover='closeregistMouseOver(this)' onmouseout='closeregistMouseOut(this)' onmousedown='closeregistMouseDown(this)' onmouseup='closeregistMouseUp(this)' />";
}
